package com.chaos.auth.service.userdetails;


import cn.hutool.core.util.ObjectUtil;
import com.chaos.auth.api.data.RbacUserData;
import com.chaos.auth.api.dto.userdetails.AdminUserDetails;
import com.chaos.auth.service.RbacUserRoleService;
import com.chaos.auth.service.RbacUserService;
import com.chaos.auth.service.auth.BaseUserDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author Jacky
 */
@Slf4j
@Component("adminByUsernameDetailsService")
public class AdminByUsernameDetailsService implements BaseUserDetailsService {
    @Resource
    private AdminDetailsService adminDetailsService;


    @Override
    public UserDetails loadUserByUsername(String username, Long tenantId) throws UsernameNotFoundException {

        RbacUserData rbacUser = adminDetailsService.getRbacUserDataByUsername(username, tenantId);
        return adminDetailsService.getAdminUserDetails(rbacUser);
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        RbacUserData rbacUser = adminDetailsService.getRbacUserDataByUsername(username);
        return adminDetailsService.getAdminUserDetails(rbacUser);
    }

}
